﻿using Sustainalytics.FileManager;
using Sustainalytics.LongRunningTaskManager.Interface;
using System;
using System.IO;

namespace Sustainalytics.LongRunningTaskManager.Tests
{
    public class MyTaskFileManager : MyTaskBase
    {
        private static readonly IFileManager _fileManager = new DiskFileManager("TaskResult");

        public static LongRunningTaskFileManagerResult ReturnValue = new LongRunningTaskFileManagerResult(
            filePath: "myUser/file.txt",
            fileManager: _fileManager);

        public override LongRunningTaskTypeEnum Type
        {
            get { return (LongRunningTaskTypeEnum)1007; }
        }

        public override object Start(LongRunningTaskContext context)
        {
            base.Start(context);

            _fileManager.AddFile(new FileContents(
                filePath: ReturnValue.FilePath,
                metadata: new FileMetadata(
                    fileName: "file.txt",
                    mimeType: "application/text",
                    dateCreated: DateTime.UtcNow),
                streamAccessor: () => File.OpenRead(@"TestFiles\file.txt")));

            return ReturnValue;
        }
    }
}
